﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using FBEntities.FBObjects;
using FBEntities.FBObjects.User;
using XFControls.XFPanels.XFPanelItems;
using FBEntities;

namespace XFItemControls.XFPanels.XFPanelItems
{
    public class XFWorkerLoadFriends : IXFItemLoadingWorker
    {
        private FBPerson _pers;
        public XFWorkerLoadFriends(FBPerson pers)
        {
            _pers = pers;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;

            if (_pers.Friends.Parsed)
                _pers.Friends.data.Clear();
            _pers.Friends.Parse(_pers.id);
        }

        #endregion
    }

    public class XFWorkerLoadProfile : IXFItemLoadingWorker
    {
        private FBPerson _pers;
        public FBPerson ParsedPersion { get { return _pers; } }
        public XFWorkerLoadProfile(FBPerson pers)
        {
            _pers = pers;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Activities.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Interests.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Music.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Television.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Movies.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Books.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Events.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Statuses.Parse(_pers.id);
            FBEntities.FBCache.BlockNextCache = true;
            _pers.Parse();
        }

        #endregion
    }

    public class XFWorkerLoadWall : IXFItemLoadingWorker
    {
        private FBPerson _pers;
        public FBPerson ParsedPersion { get { return _pers; } }
        public XFWorkerLoadWall(FBPerson pers)
        {
            _pers = pers;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;

            if (_pers.Feed.Parsed)
                _pers.Feed.data.Clear();
            _pers.Feed.Parse(_pers.id);
        }

        #endregion
    }

    public class XFWorkerLoadComments : IXFItemLoadingWorker
    {
        private FBPost _post;
        public FBPost ParsedPost { get { return _post; } }
        public XFWorkerLoadComments(FBPost post)
        {
            _post = post;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;

            if (_post.Comments.Parsed)
                _post.Comments.data.Clear();
            _post.Comments.Parse(_post.id);
        }

        #endregion
    }

    public class XFWorkerLoadNewsFeeds : IXFItemLoadingWorker
    {
        private FBPerson _pers;
        public FBPerson ParsedPersion { get { return _pers; } }
        public XFWorkerLoadNewsFeeds(FBPerson pers)
        {
            _pers = pers;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;

            if (_pers.Home.Parsed)
                _pers.Home.data.Clear();
            _pers.Home.Parse(_pers.id);
        }

        #endregion
    }

    public class XFWorkerLoadInbox : IXFItemLoadingWorker
    {
        private FBPerson _pers;
        public FBPerson ParsedPersion { get { return _pers; } }
        public XFWorkerLoadInbox(FBPerson pers)
        {
            _pers = pers;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            FBEntities.FBCache.BlockNextCache = true;

            if (_pers.Inbox.Parsed)
                _pers.Inbox.data.Clear();
            _pers.Inbox.Parse(_pers.id);
        }

        #endregion
    }

    public class XFWorkerPostLike : IXFItemLoadingWorker
    {
        public bool Success { get; set; }

        private bool _remove;
        private FBPost _post;
        public FBPost ParsedPost { get { return _post; } }
        public XFWorkerPostLike(FBPost post, bool remove)
        {
            _remove = remove;
            _post = post;
        }
        #region IXFItemLoadingWorker Members

        public void DoWork()
        {
            Success = _post.Like(_remove);
        }

        #endregion
    }
}
